package org.example.leetCode;

/**
 * @author Vader
 * @date 2021/11/4
 **/
public class GetTbId {
    public static void main(String[] args) {
        String link = "id=642047410640";
//                "&spm=a21bo.jianhua.201876.11.5af911d9cicXYP&scm=1007.34127.211940.0&pvid=217abf24-10ca-467f-bdac-5e5b4a174029";
        System.out.println(getTbId(link));
    }

    public static String getTbId(String link) {
        int i = link.indexOf("=");
        if (link.contains("&")) {
            int j = link.indexOf("&");
            return link.substring(i + 1, j);
        } else {
            char[] chars = link.toCharArray();
            StringBuffer id = new StringBuffer();
            for (int index = i+1; index < chars.length && '0' <= chars[index] && chars[index] <= '9'; index++) {
                id.append(chars[index]);
            }
            return String.valueOf(id);
        }
    }
}
